<template>
  <div class="not-found-container">
    <!-- 背景装饰元素 -->
    <div class="background-shapes">
      <div class="shape circle"></div>
      <div class="shape square"></div>
      <div class="shape triangle"></div>
    </div>

    <!-- 主内容区 -->
    <div class="content">
      <!-- 404数字动画 -->
      <div class="error-number">
        <span class="digit" :class="{ animate: animateDigits }">4</span>
        <span class="digit zero" :class="{ animate: animateDigits }">0</span>
        <span class="digit" :class="{ animate: animateDigits }">4</span>
      </div>

      <!-- 错误信息 -->
      <h1 class="error-title" :class="{ fadeIn: showContent }">页面不见了</h1>
      <p class="error-message" :class="{ fadeIn: showContent }">
        抱歉，您访问的页面不存在或已被移除
      </p>

      <!-- 交互按钮 -->
      <div class="actions" :class="{ fadeIn: showContent }">
        <button @click="goHome" class="btn primary">
          <i class="icon-home"></i> 返回首页
        </button>
        <button @click="goBack" class="btn secondary">
          <i class="icon-arrow-left"></i> 返回上一页
        </button>
      </div>

      <!-- 搜索框 -->
      <div class="search-box" :class="{ fadeIn: showContent }">
        <input 
          type="text" 
          placeholder="搜索其他内容..." 
          v-model="searchQuery"
          @keyup.enter="handleSearch"
        >
        <button @click="handleSearch" class="search-btn">
          <i class="icon-search"></i>
        </button>
      </div>
    </div>

    <!-- 页脚 -->
    <footer :class="{ fadeIn: showContent }">
      <p>© {{ new Date().getFullYear() }} 您的网站名称 - 所有权利保留</p>
    </footer>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'

// 状态定义
const animateDigits = ref(false)
const showContent = ref(false)
const searchQuery = ref('')
const router = useRouter()

// 生命周期钩子
onMounted(() => {
  // 动画序列控制
  setTimeout(() => {
    animateDigits.value = true
  }, 300)

  setTimeout(() => {
    showContent.value = true
  }, 1200)
})

// 方法定义
const goHome = () => {
  router.push('/')
}

const goBack = () => {
  window.history.back()
}

const handleSearch = () => {
  if (searchQuery.value.trim()) {
    // 实现搜索逻辑
    console.log('搜索内容:', searchQuery.value)
    // 示例: router.push(`/search?query=${searchQuery.value}`)
  }
}
</script>

<style scoped>
.not-found-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background-color: #f8f9fa;
  position: relative;
  overflow: hidden;
  padding: 20px;
  box-sizing: border-box;
}

/* 背景装饰 */
.background-shapes {
  position: absolute;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.shape {
  position: absolute;
  opacity: 0.1;
}

.circle {
  width: 300px;
  height: 300px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4361ee, #3f37c9);
  top: -150px;
  right: -150px;
  animation: float 25s infinite ease-in-out;
}

.square {
  width: 200px;
  height: 200px;
  background: linear-gradient(135deg, #f72585, #4cc9f0);
  bottom: -100px;
  left: -100px;
  animation: float 20s infinite ease-in-out;
  animation-delay: 2s;
}

.triangle {
  width: 0;
  height: 0;
  border-left: 150px solid transparent;
  border-right: 150px solid transparent;
  border-bottom: 250px solid #4895ef;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(30deg);
  animation: float 30s infinite ease-in-out;
  animation-delay: 5s;
}

/* 404数字样式 */
.error-number {
  font-size: clamp(120px, 30vw, 250px);
  font-weight: 900;
  letter-spacing: -10px;
  margin-bottom: 20px;
  position: relative;
  color: #333;
}

.digit {
  position: relative;
  display: inline-block;
  opacity: 0;
  transform: translateY(50px);
  transition: all 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.digit.animate {
  opacity: 1;
  transform: translateY(0);
}

.digit:nth-child(1) {
  transition-delay: 0.2s;
}

.digit.zero {
  color: #4361ee;
  transition-delay: 0.5s;
  margin: 0 -20px;
  text-shadow: 0 5px 15px rgba(67, 97, 238, 0.3);
}

.digit:nth-child(3) {
  transition-delay: 0.8s;
}

/* 文本内容样式 */
.error-title {
  font-size: clamp(24px, 5vw, 40px);
  margin: 0 0 15px 0;
  color: #2d3748;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.6s ease-out;
  transition-delay: 0.3s;
}

.error-message {
  font-size: clamp(16px, 3vw, 18px);
  color: #4a5568;
  max-width: 500px;
  text-align: center;
  margin: 0 0 30px 0;
  line-height: 1.6;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.6s ease-out;
  transition-delay: 0.5s;
}

/* 按钮样式 */
.actions {
  display: flex;
  gap: 15px;
  margin-bottom: 40px;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.6s ease-out;
  transition-delay: 0.7s;
}

.btn {
  padding: 12px 24px;
  border-radius: 30px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  border: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.primary {
  background-color: #4361ee;
  color: white;
  box-shadow: 0 4px 14px rgba(67, 97, 238, 0.3);
}

.primary:hover {
  background-color: #3a56d4;
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(67, 97, 238, 0.4);
}

.secondary {
  background-color: white;
  color: #4a5568;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.05);
}

.secondary:hover {
  background-color: #f7fafc;
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
}

/* 搜索框样式 */
.search-box {
  display: flex;
  width: 100%;
  max-width: 500px;
  margin-bottom: 60px;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.6s ease-out;
  transition-delay: 0.9s;
}

.search-box input {
  flex: 1;
  padding: 14px 20px;
  border: 1px solid #e2e8f0;
  border-radius: 30px 0 0 30px;
  font-size: 16px;
  outline: none;
  transition: all 0.3s ease;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
}

.search-box input:focus {
  border-color: #4361ee;
  box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
}

.search-btn {
  background-color: #4361ee;
  color: white;
  border: none;
  padding: 0 20px;
  border-radius: 0 30px 30px 0;
  cursor: pointer;
  transition: all 0.3s ease;
}

.search-btn:hover {
  background-color: #3a56d4;
}

/* 页脚样式 */
footer {
  position: absolute;
  bottom: 20px;
  color: #94a3b8;
  font-size: 14px;
  opacity: 0;
  transition: all 0.6s ease-out;
  transition-delay: 1.1s;
}

/* 动画效果类 */
.fadeIn {
  opacity: 1 !important;
  transform: translateY(0) !important;
}

/* 动画关键帧 */
@keyframes float {
  0% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(-30px) rotate(5deg);
  }
  100% {
    transform: translateY(0) rotate(0deg);
  }
}

/* 图标样式 */
.icon-home::before {
  content: '⌂';
  font-size: 18px;
}

.icon-arrow-left::before {
  content: '←';
  font-size: 18px;
}

.icon-search::before {
  content: '🔍';
  font-size: 18px;
}

/* 响应式调整 */
@media (max-width: 768px) {
  .error-number {
    letter-spacing: -5px;
  }
  
  .digit.zero {
    margin: 0 -10px;
  }
  
  .actions {
    flex-direction: column;
    width: 100%;
    max-width: 300px;
  }
  
  .btn {
    width: 100%;
    justify-content: center;
  }
}
</style>